package com.cndw.kungfu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.cndw.kungfu.comm.AccessClose;
import com.cndw.kungfu.comm.tencent.LogFieldType;
import com.cndw.kungfu.comm.tencent.QQDC;
import com.cndw.kungfu.config.ConstantsAct;
import com.cndw.kungfu.config.ConstantsCost;
import com.cndw.kungfu.config.ConstantsDayIntKey;
import com.cndw.kungfu.config.ConstantsIntKey;
import com.cndw.kungfu.config.ConstantsLevel;
import com.cndw.kungfu.config.ConstantsLog;
import com.cndw.kungfu.config.GoodsEffectConfig;
import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.domain.TaskMode;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.ext.StringProcesser;
import com.cndw.kungfu.ext.TimeProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.disciple.PlayerMartial;
import com.cndw.kungfu.model.goods.domain.SubPops;
import com.cndw.kungfu.model.goods.domain.SysModeAwards;
import com.cndw.kungfu.model.player.domain.Artifact;
import com.cndw.kungfu.model.player.domain.ArtifactSub;
import com.cndw.kungfu.model.sys.LogServer;
import com.cndw.rpg.annotation.Controller;
import com.cndw.rpg.framework.ResponseMessage;
import com.cndw.rpg.framework.Session;

@Controller
public class ActSmallController {
	/**
	 * 918活动综合显示
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	public ResponseMessage show(Session session, int type) {
		if (type < 150) {//每次最小值
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		switch (type) {
		case 101:
			int xs = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.xs);
			int xsg = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.xsg);
			map.put("xs", xs);
			map.put("xsg", xsg);
			break;
		case 102:

			map.put("xw", player.getDataInfo().getEveryDay().getDailyScore());
			map.put("xwg", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.xwg));
			break;
		case 103:// 每日人物
			int taskg = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.taskg);
			int[] taskNum = new int[5];
			taskNum[0] = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.fruit);
			taskNum[1] = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeDart);
			taskNum[2] = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeUnionCycle);
			taskNum[3] = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.lInAct);
			taskNum[4] = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeDaily);
			map.put("taskNum", taskNum);
			map.put("taskg", taskg);
			break;
		case 111:// 显示招聘积分
			map.put("rds", player.getDataInfo().intDataGet(ConstantsIntKey.trd));
			break;
		case 112:// 嫦娥后羿活动
			PlayerMartial playerMartial = Context.getDiscipleServer().getByPlayerId(session.getUid());
			int zp = playerMartial.findSpcSign(ConstantsAct.spcDiscipleSign);
			int zpg = player.getDataInfo().intDataGet(ConstantsIntKey.trg);
			map.put("zp", zp);
			map.put("zpg", zpg);
			break;
		case 113:
			map.put("dp", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dp));
			map.put("dpg", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dpg));
			break;
		case 121://每日登录奖励
			map.put("dlg", (player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm) & ConstantsDayIntKey.comm_2) > 0);
			break;
		case 122://灵性活动
			map.put("sg", player.getDataInfo().intDataGet(ConstantsIntKey.sg));
			map.put("spirit", player.getDataInfo().getMaxSpirit());
			break;
		case 131://充值活动
			int payc = Context.getBusinessServer().selectPeriodPaySum(player, ConstantsAct.payAwardTime[0], ConstantsAct.payAwardTime[1]);
			map.put("payc", payc);
			map.put("payg", player.getDataInfo().intDataGet(ConstantsIntKey.tpg));
			break;
		case 132://登山活动
			map.put("mg", player.getDataInfo().intDataGet(ConstantsIntKey.tmg));
			map.put("ma", player.getDataInfo().intDataGet(ConstantsIntKey.tma));
			break;
		case 141://登录活动
			map.put("share", player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_6) );
			map.put("happy", player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_7) );
			map.put("ltime", player.getTodayOnLine());
			break;
		case 142://财神赐福
			map.put("t", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.prayCounts));
			map.put("g", (player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm) & ConstantsDayIntKey.comm_5) > 0);
			break;
		case 151://神器境界
			map.put("a1g", player.getDataInfo().intDataGet(ConstantsIntKey.ta1g));
			map.put("a2g", player.getDataInfo().intDataGet(ConstantsIntKey.ta2g));
			Artifact artifact = player.getDataInfo().getArtifact();
			if (artifact != null) {
				for (Entry<Integer, ArtifactSub> e : artifact.getSubs().entrySet()) {
					map.put("a" + e.getKey().toString(), e.getValue().getLevel());
				}
			}
			break;
		case 152: //光棍节登录活动
			int pays = Context.getBusinessServer().selectPeriodPaySum(player, TimeProcesser.getMorningTime(), TimeProcesser.getUnixTime());
			map.put("bye", player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_8) );
			map.put("sweet", player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_9) );
			map.put("payc", pays > 0);
			break;
		case 153://光棍节乐享洗练活动
			map.put("wget", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twg));
			map.put("wtimes", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twa));
			break;
		case 154://神器四项精魄
			Artifact act = player.getDataInfo().getArtifact();
			if (act != null) {
				int[] finishCount = new int[4];
				int[] tmp;
				for (Entry<Integer, ArtifactSub> e : act.getSubs().entrySet()) {
					tmp = e.getValue().getFourBuffState(e.getKey());
					for (int i = 0; i < tmp.length; i++) {
						finishCount[i] += tmp[i];
					}
				}
				map.put("fcount", finishCount);
				map.put("fbg", player.getDataInfo().intDataGet(ConstantsIntKey.tfbg));
			}
			break;
		case 161://温馨初冬登录活动
			map.put("today", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twlb));
			map.put("five", player.getDataInfo().intDataGet(ConstantsIntKey.twbb));
			map.put("wtimes", player.getDataInfo().intDataGet(ConstantsIntKey.twt)); //已领取次数
			break;
		case 162://华山崇圣
			map.put("f", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twf));
			map.put("fg", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tfg));
			break;
		case 163://温馨初冬徒弟成长
			map.put("dwp0", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dwp0)); //普通洗点次数
			map.put("dwp1", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dwp1)); //白金洗点次数
			map.put("dwp2", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dwp2)); //至尊洗点次数
			map.put("flash", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twdb));
			break;
		default:
			break;
		}
		map.put("type", type);
		QQDC.getInstance().logClick(player, LogFieldType.actsmall);
		return ResponseMessage.getSuccMessage(map);
	}
	@Deprecated
	@AccessClose
	public ResponseMessage xsAward(Session session, int type) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int xs = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.xs);
		int xsg = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.xsg);
		int awardSign = xsg + 1;
		if (awardSign > ConstantsAct.xs.length || xs < ConstantsAct.xs[xsg]) {
			return null;
		}
		if (type != awardSign) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("actsmall.xs.errtype"));
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.xsg, awardSign);
		player.getDataInfo().commitSync();
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsAct.xsAwardId, ConstantsAct.xsAward[awardSign], 1);
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsAct.xsAwardId);
		LogServer.recordLog(player, ConstantsLog.activity, 90421, goodsMode.getName(), ConstantsAct.xsAward[awardSign], xs);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("xsg", awardSign);

		return ResponseMessage.getSuccMessage(map);
	}
	@Deprecated
	@AccessClose
	public ResponseMessage xwBuy(Session session, int type) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int xw = player.getDataInfo().getEveryDay().getDailyScore();
		int xwg = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.xwg);
		int awardSign = xwg + 1;
		if (awardSign > ConstantsAct.xw.length || xw < ConstantsAct.xw[xwg]) {
			return null;
		}
		if (type != awardSign) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("actsmall.xw.errtype"));
		}
		int num = ConstantsAct.xwBuy[xwg];
		int costGold = ConstantsAct.xwAward[1] * num;
		if (player.getGoldAll() < costGold) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		player.alterGoldAll(-costGold);
		LogServer.costEventLog(player.getPlayerId(), costGold, ConstantsCost.xwBuySTLGold);

		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.xwg, awardSign);
		player.commitSync();
		player.getDataInfo().commitSync();
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsAct.xwAward[0], num, 1);
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsAct.xwAward[0]);
		LogServer.recordLog(player, ConstantsLog.activity, 90422, type, costGold, num, goodsMode.getName());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("xwg", awardSign);
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());

		return ResponseMessage.getSuccMessage(map);
	}
	@Deprecated
	@AccessClose
	public ResponseMessage taskAward(Session session, int type) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());

		int taskg = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.taskg);
		if ((taskg & (1 << type)) > 0) {
			return null;
		}

		int[] taskNum = new int[5];
		taskNum[0] = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.fruit);
		taskNum[1] = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeDart);
		taskNum[2] = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeUnionCycle);
		taskNum[3] = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.lInAct);
		taskNum[4] = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeDaily);
		int[] awardArr = ConstantsAct.taskAward[type];
		if (taskNum[type] < awardArr[0]) {
			return null;
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		taskg = taskg | (1 << type);

		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.taskg, taskg);
		player.getDataInfo().commitSync();
		Context.getGoodsServer().giveGoodsBing(session.getUid(), awardArr[1], awardArr[2], 1);
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(awardArr[1]);
		LogServer.recordLog(player, ConstantsLog.activity, 90423, type, goodsMode.getName(), awardArr[2]);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("taskg", taskg);

		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 徒弟洗点积分
	 * @param session
	 * @param type
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage dpAward(Session session,int type){
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int dp = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dp);
		int dpg = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dpg);
		int awardSign = dpg + 1;
		if (awardSign > ConstantsAct.dp.length || dp < ConstantsAct.dp[dpg]) {
			return null;
		}
		if (type != awardSign) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("actsmall.xs.errtype"));
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.dpg, awardSign);
		player.getDataInfo().commitSync();
		int[] awardArr = ConstantsAct.dpAward[dpg];
		
		Context.getGoodsServer().giveGoodsBing(session.getUid(),awardArr[0], awardArr[1], 1);
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(awardArr[0]);
		LogServer.recordLog(player, ConstantsLog.activity, 90452, dpg,goodsMode.getName(), awardArr[1]);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dpg", awardSign);
		
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 领取每日登录奖励 
	 * @param session
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage dlAward(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv30actLoginAward) {
			return null;
		}
		
		int  comm = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm);
		if ((comm & ConstantsDayIntKey.comm_2) > 0) {
			return null;
		}
		
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsAct.dlAwardId, 1, 1);
		
		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.comm, comm | ConstantsDayIntKey.comm_2);
		player.getDataInfo().commitSync();
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsAct.dlAwardId);
		LogServer.recordLog(player, ConstantsLog.activity, 90461, goodsMode.getName(), 1);
		return ResponseMessage.getSuccMessage(true);
	}
	
	/**
	 * 灵性活动奖励领取
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage spiritAward(Session session, int type) {
		if (type < 1 || type > 6) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int maxSpirit = player.getDataInfo().getMaxSpirit();
		int sg = player.getDataInfo().intDataGet(ConstantsIntKey.sg);
		int awardSign = sg + 1;
		if (awardSign > ConstantsAct.spirit.length || maxSpirit < ConstantsAct.spirit[sg]) {
			return null;
		}
		if (type != awardSign) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("actsmall.xs.errtype"));
		}
		
		StringBuffer logSB = new StringBuffer();
		SysModeAwards sysAwards = SysModeAwards.get(102, awardSign);
		if (sysAwards != null) {
			List<SubPops> subPops = sysAwards.getSubPopsList();
			int black = Context.getGoodsServer().checkSubPopsBlack(subPops);
			if (!player.getPlayerBoxs().checkBlack(black)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", black));
			}
//			Context.getGoodsServer().giveSubPops(subPops, player, logSB);
		}
		player.getDataInfo().intDataSet(ConstantsIntKey.sg, awardSign);
		player.getDataInfo().commitSync();
		
		LogServer.recordLog(player, ConstantsLog.activity, 90462, type, logSB.toString());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("sg", awardSign);

		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 充值活动奖励领取
	 * 			2012-10-30号结束
	 * 
	 * @param session
	 * @param type
	 * @return
	 * 
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage payAward(Session session, int type) { 
		if (type < 1 || type > 3) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int payg =  player.getDataInfo().intDataGet(ConstantsIntKey.tpg);
		int awardSign = payg + 1;
		if (awardSign != type) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("actsmall.xs.errtype"));
		}
		int payCash = Context.getBusinessServer().selectPeriodPaySum(player, ConstantsAct.payAwardTime[0], ConstantsAct.payAwardTime[1]);
		if (payCash < ConstantsAct.payAwardNeed[payg]) {
			return null;
		}
		
		StringBuffer logSB = new StringBuffer();
		SysModeAwards sysAwards = SysModeAwards.get(2001, awardSign);
		if (sysAwards != null) {
			List<SubPops> subPops = sysAwards.getSubPopsList();
			int black = Context.getGoodsServer().checkSubPopsBlack(subPops);
			if (!player.getPlayerBoxs().checkBlack(black)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", black));
			}
			//Context.getGoodsServer().giveSubPops(subPops, player, logSB);
		}
		player.getDataInfo().intDataSet(ConstantsIntKey.tpg, awardSign);
		player.getDataInfo().commitSync();
		
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120003, type, logSB.toString(), payCash);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("payg", awardSign);
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 登山活动奖励领取
	 * 				2012-10-30号结束
	 * @param session
	 * @param type
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage mountainAward(Session session, int type) {
		if (type < 1 || type > 7) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int ma = player.getDataInfo().intDataGet(ConstantsIntKey.tma);
		int mg = player.getDataInfo().intDataGet(ConstantsIntKey.tmg);
		int awardSign = mg + 1;
		if (awardSign > ma) {
			return null;
		}
		if (awardSign != type) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("actsmall.xs.errtype"));
		}
		
		StringBuffer logSB = new StringBuffer();
		SysModeAwards sysAwards = SysModeAwards.get(2002, awardSign);
		if (sysAwards != null) {
			List<SubPops> subPops = sysAwards.getSubPopsList();
			int black = Context.getGoodsServer().checkSubPopsBlack(subPops);
			if (!player.getPlayerBoxs().checkBlack(black)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", black));
			}
			Context.getGoodsServer().giveSubPops(subPops, player, logSB);
		}
		player.getDataInfo().intDataSet(ConstantsIntKey.tmg, awardSign);
		player.getDataInfo().commitSync();
		
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120002, type, logSB.toString(), ma);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mg", player.getDataInfo().intDataGet(ConstantsIntKey.tmg));
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 *  万圣节登录活动奖励领取
	 *  			2012-10-30号开始
	 * 				2012-11-06号结束
	 * @param session
	 * @param type
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage loginHalloweenAward(Session session,int type) {
		if(type < 0 || type > 1) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		//判断等级是否大于30级
		if(player.getLevel() < 30) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level", 30));
		}

		boolean loginGot = player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm,ConstantsDayIntKey.comm_6);
		boolean keep30Got = player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm,ConstantsDayIntKey.comm_7);
		//是否已领取礼包
		boolean haveGot = type == 0 ? loginGot: keep30Got;
		
		if(  haveGot ) {
			return null;
		}

		//判断登录是否满30分钟
		if (type == 1 && player.getTodayOnLine() < 1800) {
			return null;
		}
		if ( !player.getPlayerBoxs().checkBlack() ) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		//发礼包
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsAct.halloweenAward[type], 1, 1);
		player.getDataInfo().getEveryDay().intDataBitStatAdd(ConstantsDayIntKey.comm,type == 0?ConstantsDayIntKey.comm_6 : ConstantsDayIntKey.comm_7);
		player.getDataInfo().commitSync();
		//记录日志
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsAct.halloweenAward[type]);
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120006, type, goodsMode.getName(), 1);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("share", player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_6) );
		map.put("happy", player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_7) );
		map.put("ltime", player.getTodayOnLine());
		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 领赌神赐福奖励
	 * 			结束：2012-11-6
	 * 
	 * @param session
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage prayAward(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		
		int count =	player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.prayCounts);
		boolean todayGot = player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_5);
		if (count < 30 || todayGot) {
			return null;
		}
		
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsAct.prayAwardId, 1, 1);
		player.getDataInfo().getEveryDay().intDataBitStatAdd(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_5);
		player.getDataInfo().commitSync();
		
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsAct.prayAwardId);
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120007, goodsMode.getName(),1);
		
		return ResponseMessage.getSuccMessage(true);
	}
	/**
	 * 领取神器境界奖励
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage actStateAward(Session session, int actId, int type) {
		if (actId < 1 || actId > 2 || type < 0 || type > 4) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		
		String key = actId == 1 ? ConstantsIntKey.ta1g : ConstantsIntKey.ta2g;
		int g = player.getDataInfo().intDataGet(key);
		if ((g & 1 << type) > 0) {
			return null;
		}
//		if (awardSign != type) {
//			return ResponseMessage.ticpErrMsg(LanguageLib.get("actsmall.xs.errtype"));
//		}
		Artifact artifact = player.getDataInfo().getArtifact();
		if (artifact == null) {
			return null;
		}
		ArtifactSub aSub = artifact.getSub(actId);
		if (aSub == null) {
			return null;
		}
		if (aSub.getLevel() < ConstantsAct.actStateAward[type][0]) {
			return null;
		}
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsAct.actStateAward[type][1]);
		int needSize = NumberProcesser.ceil(ConstantsAct.actStateAward[type][2], goodsMode.getMaxStack());
		if (!player.getPlayerBoxs().checkBlack(needSize)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", needSize));
		}
		
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsAct.actStateAward[type][1], ConstantsAct.actStateAward[type][2], 1);
		
		player.getDataInfo().intDataSet(key, g | 1 << type);
		player.getDataInfo().commitSync();
		
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120010, type, actId, aSub.getLevel(),goodsMode.getName(), ConstantsAct.actStateAward[type][2]);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("a1g", player.getDataInfo().intDataGet(ConstantsIntKey.ta1g));
		map.put("a2g", player.getDataInfo().intDataGet(ConstantsIntKey.ta2g));
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 *  光棍节登录活动奖励领取
	 *  			2012-11-06号开始
	 * 				2012-11-12号结束
	 * @param session
	 * @param type
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage singleAward(Session session,int type) {
		if(type < 0 || type > 1) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if( type == 0 && player.getLevel() < ConstantsLevel.lv30single) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv30single);
		}

		boolean haveGot = player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, type == 0?ConstantsDayIntKey.comm_8 : ConstantsDayIntKey.comm_9);
		if ( haveGot ) {
			return null;
		}
		
		int payc = Context.getBusinessServer().selectPeriodPaySum(player, TimeProcesser.getMorningTime(), TimeProcesser.getUnixTime());
		if( type == 1 && payc <= 0) {
			return null;
		}
		
		if ( !player.getPlayerBoxs().checkBlack() ) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}

		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsAct.singleAward[type], 1, 1);
		player.getDataInfo().getEveryDay().intDataBitStatAdd(ConstantsDayIntKey.comm, type == 0?ConstantsDayIntKey.comm_8 : ConstantsDayIntKey.comm_9);
		player.getDataInfo().commitSync();
		
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsAct.singleAward[type]);
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120008, type, goodsMode.getName(), 1);
			
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("bye", player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_8 ));
		map.put("sweet", player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.comm, ConstantsDayIntKey.comm_9 ));
		map.put("payc", payc > 0);
		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 光棍节的乐享洗练活动
	 * 		2012-11-06号开始
	 * 		2012-11-13号结束
	 * @param session
	 * @param type
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage washAward(Session session ,int type) {
		if(type < 0 || type >4) {
			return null;
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if(player.getLevel() < ConstantsLevel.lv60wash) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv60wash);
		}
		boolean haveGot = player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.twg, 1 << type);
		if (haveGot) {
			return null;
		}
		//拿到兵魄洗练次数
		int twa = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twa);
		if (twa < ConstantsAct.washAwards[type]) {
			return null;
		}
		
		StringBuffer logSB = new StringBuffer();
		SysModeAwards sysAwards = SysModeAwards.get(2003, type + 1);
		if (sysAwards != null) {
			List<SubPops> subPops = sysAwards.getSubPopsList();
			int black = Context.getGoodsServer().checkSubPopsBlack(subPops);
			if (!player.getPlayerBoxs().checkBlack(black)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", black));
			}
			Context.getGoodsServer().giveSubPops(subPops, player, logSB);
		}
	
		player.getDataInfo().getEveryDay().intDataBitStatAdd(ConstantsDayIntKey.twg, 1 << type);
		player.getDataInfo().commitSync();
		
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120009, type, logSB.toString());
			
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("wget", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twg));
		map.put("wtimes", twa);
		return ResponseMessage.getSuccMessage(map);
	}
	/**
	 * 领取神器四项精魄奖励
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	@Deprecated
	@AccessClose
	public ResponseMessage actFbAward(Session session, int type) {
		if (type < 0 && type > 3) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int fbg = player.getDataInfo().intDataGet(ConstantsIntKey.tfbg);
		if ((fbg & 1 << type) > 0) {
			return null;
		}
		
		Artifact act = player.getDataInfo().getArtifact();
		int[] finishCount = new int[4];//达到条件精魄数量
		if (act != null) {
			int[] tmp;
			for (Entry<Integer, ArtifactSub> e : act.getSubs().entrySet()) {
				tmp = e.getValue().getFourBuffState(e.getKey());
				for (int i = 0; i < tmp.length; i++) {
					finishCount[i] += tmp[i];
				}
			}
		}
		if (finishCount[type] < 3) {
			return null;
		}
		
		StringBuffer logSB = new StringBuffer();
		SysModeAwards sysAwards = SysModeAwards.get(2004, type + 1);
		if (sysAwards != null) {
			List<SubPops> subPops = sysAwards.getSubPopsList();
			int black = Context.getGoodsServer().checkSubPopsBlack(subPops);
			if (!player.getPlayerBoxs().checkBlack(black)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", black));
			}
			Context.getGoodsServer().giveSubPops(subPops, player, logSB);
		}
		fbg = fbg | 1 << type;
		player.getDataInfo().intDataSet(ConstantsIntKey.tfbg, fbg);
		player.getDataInfo().commitSync();
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120013, type, StringProcesser.toString(finishCount), logSB.toString());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("fbg", fbg);
		return ResponseMessage.getSuccMessage(map);
	}
	/**
	 * 领取崇圣活动奖励
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	public ResponseMessage fcAward(Session session, int type) {
		if (type < 1 && type > 5) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int fg = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tfg);
		int fNum = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twf);
		int awardSign = fg + 1;
		if (awardSign > ConstantsAct.flowerCrossAward.length || fNum < ConstantsAct.flowerCrossAward[fg][0]) {
			return null;
		}
		if (awardSign != type) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("actsmall.xs.errtype")); 
		}
		
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		Context.getGoodsServer().giveGoodsBing(session.getUid(), 103511, ConstantsAct.flowerCrossAward[fg][1], 1);
		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.tfg, awardSign);
		player.getDataInfo().commitSync();
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(103511);
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120016, type, goodsMode.getName(), ConstantsAct.flowerCrossAward[fg][1], fNum);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("fg", awardSign);
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 温馨初冬登录活动
	 * 				11月13日维护后-11月19日23:59:59
	 * @param session
	 * @param type
	 * @return
	 */
	public ResponseMessage winterAward(Session session,int type) {
		if(type < 0 || type > 1){
			return null;
		}
		if( TimeProcesser.getUnixTime() > TimeProcesser.getUnixTimeSilent("2012-11-19 23:59:59")) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr"));
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if( player.getLevel() < ConstantsLevel.lv30Winter	) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv30Winter);
		}
		boolean todayGot = type == 0 && player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twlb) > 0;
		boolean fiveGot = type == 1 && player.getDataInfo().intDataGet(ConstantsIntKey.twbb) > 0;
		if (todayGot || fiveGot) {
			return null;
		}
		if(type == 1 && player.getDataInfo().intDataGet(ConstantsIntKey.twt) < 5) {
			return null;
		}
	
		StringBuffer logSB = new StringBuffer();
		SysModeAwards sysAwards = SysModeAwards.get(2006, type + 1);
		if (sysAwards != null) {
			List<SubPops> subPops = sysAwards.getSubPopsList();
			int black = Context.getGoodsServer().checkSubPopsBlack(subPops);
			if (!player.getPlayerBoxs().checkBlack(black)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", black));
			}
			Context.getGoodsServer().giveSubPops(subPops, player, logSB);
		}
	
		if(type == 0) {
			player.getDataInfo().intDataAlter(ConstantsIntKey.twt, 1);
			player.getDataInfo().getEveryDay().intDataAlter(ConstantsDayIntKey.twlb, 1);
		} else {
			player.getDataInfo().intDataAlter(ConstantsIntKey.twbb, 1);
		}
		
		player.getDataInfo().commitSync();
		
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120017, type, logSB.toString());
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("today", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twlb));
		map.put("five", player.getDataInfo().intDataGet(ConstantsIntKey.twbb));
		map.put("wtimes", player.getDataInfo().intDataGet(ConstantsIntKey.twt)); //已领取次数
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 温馨初冬徒弟成长
	 * 				11月13日维护后-11月20日维护前
	 * @param session
	 * @param type
	 * @return
	 */
	public ResponseMessage discipleAward(Session session,int type) {
		if(type < 0 || type > 5){
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		
		boolean haveGot = player.getDataInfo().getEveryDay().intDataStatContants(ConstantsDayIntKey.twdb, 1 << type);
		if (haveGot) {
			return null;
		}
		
		int xd = 0,goodsIndex = 0;
		if(type < 2) {
			xd = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dwp0);
		} else  if( type < 4){
			xd = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dwp1);
			goodsIndex = 1;
		} else {
			xd = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dwp2);
			goodsIndex = 2;
		}
		if (xd < ConstantsAct.discipleNeed[type][0]) {
			return null;
		}
		
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(GoodsEffectConfig.disBaoFuIds[goodsIndex]);
		int needSize = NumberProcesser.ceil(ConstantsAct.discipleNeed[type][1], goodsMode.getMaxStack());
		if (!player.getPlayerBoxs().checkBlack(needSize)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", needSize));
		}
		Context.getGoodsServer().giveGoodsBing(session.getUid(), GoodsEffectConfig.disBaoFuIds[goodsIndex], ConstantsAct.discipleNeed[type][1], 1);
		
		player.getDataInfo().getEveryDay().intDataBitStatAdd(ConstantsDayIntKey.twdb, 1 << type);
		player.getDataInfo().commitSync();
		
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120018, type,goodsMode.getName(), ConstantsAct.discipleNeed[type][1]);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("flash", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.twdb));
		return ResponseMessage.getSuccMessage(map);
	}

}
